package com.educate.device.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.educate.common.web.R;
import com.educate.device.model.bo.DeviceMessageBO;
import com.educate.device.rpc.api.DeviceMessageService;
import lombok.extern.log4j.Log4j2;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Log4j2
@RestController
@RequestMapping("deviceMessage")
public class DeviceMessageController {

    @Reference(version = "${api.service.version}",
            application = "${dubbo.application.id}",
            url = "${dubbo.application.url}")
    private DeviceMessageService deviceMessageService;

    @PostMapping(value = "/create")
    public R create(@RequestBody DeviceMessageBO bo) {
        deviceMessageService.create(bo);
        return R.ok();
    }

    @PostMapping(value = "/delete")
    public R delete(@RequestBody DeviceMessageBO bo) {
        deviceMessageService.delete(bo);
        return R.ok();
    }

    @PostMapping(value = "/delete/{deviceMessageId}")
    public R delete(@PathVariable String deviceMessageId) {
        deviceMessageService.delete(deviceMessageId);
        return R.ok();
    }

    @PostMapping(value = "/detail/{deviceMessageId}")
    public R<DeviceMessageBO> detail(@PathVariable String deviceMessageId) {
        DeviceMessageBO bo = deviceMessageService.detail(deviceMessageId);
        return R.ok(bo);
    }

    @PostMapping(value = "/detail")
    public R<DeviceMessageBO> detail(@RequestBody DeviceMessageBO bo) {
        DeviceMessageBO detail = deviceMessageService.detail(bo);
        return R.ok(detail);
    }

    @PostMapping(value = "/update")
    public R<DeviceMessageBO> update(@RequestBody DeviceMessageBO bo) {
        deviceMessageService.update(bo);
        return R.ok();
    }

    @PostMapping(value = "/query")
    public R<Page<DeviceMessageBO>> query(@RequestBody DeviceMessageBO bo) {
        Page<DeviceMessageBO> result = deviceMessageService.query(bo, bo.pageable());
        return R.ok(result);
    }

    @PostMapping(value = "/list")
    public R<List<DeviceMessageBO>> list(@RequestBody DeviceMessageBO bo) {
        List<DeviceMessageBO> result = deviceMessageService.list(bo);
        return R.ok(result);
    }

}
